﻿/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework
 * Version 2.10
 * 
 * CNR Sockets Client Command Base Class
 *      Provides an abstract base definition for implementing commands in
 * a command-and-response protocol using a sockets client.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using Adaptive.Foundation;
using Adaptive.Network.Sockets;

namespace Adaptive.Foundation.Network.Cnr
{
    /// <summary>
    /// Provides an abstract base definition for implementing commands in 
    /// a command-and-response protocol using a sockets client.
    /// </summary>
    /// <remarks>
    /// This base class is intended to be extended for the specific application within a 
    /// particular command-and-response protocol, such as FTP, E/SMTP, POP3, and others.
    /// 
    /// The specifics of each command implementation, and the related derivatives of the 
    /// <see cref="CnrResponseBase"/> implementations are left to the implementors
    /// of each protocol.
    /// 
    /// This version if the <see cref="CnrCommandBase"/> class is intended for use with 
    /// the <see cref="SocketsClient"/> class.
    /// </remarks>
    public abstract class CnrSocketsCommandBase : CnrCommandBase
    {
        /*--------------------------------------------------------------------------------
         * Private Member Declarations
         *------------------------------------------------------------------------------*/
        #region Private Member Declarations
        /// <summary>
        /// Reference to the sockets client instance to use.
        /// </summary>
        private SocketsClient _client;
        #endregion

        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="client">
        /// A reference to the <see cref="SocketsClient"/> instance used to execute the command.
        /// </param>
        /// <param name="commandName">
        /// The name of the command,
        /// </param>
        public CnrSocketsCommandBase(SocketsClient client, string commandName)
            : base(commandName)
        {
            _client = client;
        }
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <param name="client">
        /// A reference to the <see cref="SocketsClient"/> instance used to execute the command.
        /// </param>
        /// <param name="commandName">
        /// The name of the command,
        /// </param>
        /// <param name="commandValue">
        /// A numeric value that identifies the command.
        /// </param>
        public CnrSocketsCommandBase(SocketsClient client, string commandName, int commandValue)
            : base(commandName, commandValue)
        {
            _client = client;
        }
        /// <summary>
        /// Deallocates internally allocated objects.
        /// </summary>
        /// <param name="disposing">
        /// A value indicating whether the object is being disposed.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            _client = null;
            base.Dispose(disposing);
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Protected Properties
         *------------------------------------------------------------------------------*/
        #region Protected Properties
        /// <summary>
        /// Gets the reference to the client instance to use.
        /// </summary>
        /// <value>
        /// The <see cref="SocketsClient"/> instance assigned to the object.
        /// </value>
        protected SocketsClient Client
        {
            get { return _client; }
        }
        #endregion

    }
}